//
//  ReadBookVOrH_VC+FloatBtns_Pep.m
//  KidReading
//
//  Created by telen on 16/4/18.
//  Copyright © 2016年 刘赞黄Telen. All rights reserved.
//

#import "ReadBookVOrH_VC+FloatBtns_Pep.h"
#import "ConstDefine.h"

#define LineWidth_Thin_FlashPen 8
#define LineWidth_Mid_FlashPen 16
#define LineWidth_Bold_FlashPen 32
#define LineAlpha_FlashPen (0.5f)

#define LineWidth_Thin_Pen 2
#define LineWidth_Mid_Pen 4
#define LineWidth_Bold_Pen 8
#define LineAlpha_Pen 1

#define LineWidth_Thin_Eraser 14
#define LineWidth_Mid_Eraser 26
#define LineWidth_Bold_Eraser 52

#define LineColor1 [UIColor colorWithRed:1 green:1 blue:1 alpha:1]
#define LineColor2 [UIColor colorWithRed:0 green:0 blue:0 alpha:1]
#define LineColor3 [UIColor colorWithRed:(233/255.0) green:(81/255.0) blue:(70/255.0) alpha:1]
#define LineColor4 [UIColor colorWithRed:(237/255.0) green:(194/255.0) blue:(0/255.0) alpha:1]
#define LineColor5 [UIColor colorWithRed:(255/255.0) green:(157/255.0) blue:(23/255.0) alpha:1]
#define LineColor6 [UIColor colorWithRed:(163/255.0) green:(83/255.0) blue:(180/255.0) alpha:1]
#define LineColor7 [UIColor colorWithRed:(51/255.0) green:(152/255.0) blue:(226/255.0) alpha:1]
#define LineColor8 [UIColor colorWithRed:(12/255.0) green:(204/255.0) blue:(209/255.0) alpha:1]
#define LineColor9 [UIColor colorWithRed:(8/255.0) green:(203/255.0) blue:(36/255.0) alpha:1]

#define LinesRatio (0.88f)

@interface PaintToolInfo : NSObject
@property(nonatomic,strong)NSArray<UIColor*>* colorArr;
@property(nonatomic,assign)NSInteger colorIndex;
@property(nonatomic,strong)NSArray<NSString*>* penArr;
@property(nonatomic,strong)NSString* pen;
@property(nonatomic,strong)NSArray<NSString*>* lineWidthTypeArr;
@property(nonatomic,strong)NSString* lineWidthType;
@property(nonatomic,assign)BOOL isEraser;
//
@property(nonatomic,strong)NSString *pageID; //Pep统计扩展
//
- (UIColor*)color;
- (CGFloat)lineWidth;
//
@end
@implementation PaintToolInfo

- (UIColor*)color{
    UIColor* clr = nil;
    if (_colorIndex < _colorArr.count && _colorIndex >=0) {
        clr = _colorArr[_colorIndex];
        if ([_pen isEqualToString:PenChoose_bold]){
            clr = [clr colorWithAlphaComponent:LineAlpha_FlashPen];
        }
    }
    return clr;
}

- (CGFloat)lineWidth{
    CGFloat line = 0;
    if (_isEraser) {//橡皮
        if ([_lineWidthType isEqualToString:LineChoose_thin]) {
            line = LineWidth_Thin_Eraser;
        }
        else if ([_lineWidthType isEqualToString:LineChoose_normal]){
            line = LineWidth_Mid_Eraser;
        }
        else if ([_lineWidthType isEqualToString:LineChoose_bold]){
            line = LineWidth_Bold_Eraser;
        }
    }
    else if ([_pen isEqualToString:PenChoose_thin]) {//白板笔
        if ([_lineWidthType isEqualToString:LineChoose_thin]) {
            line = LineWidth_Thin_Pen;
        }
        else if ([_lineWidthType isEqualToString:LineChoose_normal]){
            line = LineWidth_Mid_Pen;
        }
        else if ([_lineWidthType isEqualToString:LineChoose_bold]){
            line = LineWidth_Bold_Pen;
        }
    }
    else if ([_pen isEqualToString:PenChoose_bold]) {//荧光笔
        if ([_lineWidthType isEqualToString:LineChoose_thin]) {
            line = LineWidth_Thin_FlashPen;
        }
        else if ([_lineWidthType isEqualToString:LineChoose_normal]){
            line = LineWidth_Mid_FlashPen;
        }
        else if ([_lineWidthType isEqualToString:LineChoose_bold]){
            line = LineWidth_Bold_FlashPen;
        }
    }
    return line;
}



- (void)setIsEraser:(BOOL)isEraser {
    _isEraser = isEraser;
    //Pep统计：橡皮擦
    ReadBookVOrH_VC *vc = [ReadBookVOrH_VC currentReadInstance];
    NSString *pageStr = self.pageID;
    if (pageStr) {
        BOOL isBegin = isEraser;
        NSDictionary *opDict = [NSDictionary dictionaryWithObjectsAndKeys:@"erase",@"op",@(vc.bookid).description, @"bid",pageStr,@"pg",@(1).description,@"opc", nil];
        [NSObject msgToTarget:vc menthed:@"pepSatisticSrouce_read:isBegin:" refs:@[opDict,@(isBegin)] needReturnValue:NO];
    }
}

@end


@interface ReadBookVOrH_VC()
@property(nonatomic,strong)FloatBtnView_Pep* pFView;
@property(nonatomic,strong)StatusButton_3_View* pFHomeBtn;
@property(nonatomic,strong)StatusButton_2_View* pNotesModelBtn;
@property(nonatomic,strong)StatusButton_2_View* pGrammarModelBtn;
@property(nonatomic,strong)StatusButton_2_View* pWordsModelBtn;
@property(nonatomic,strong)StatusButton_2_View* pTransModelBtn;
@property(nonatomic,strong)StatusButton_2_View* pReadModelBtn;
//
@property(nonatomic,strong)StatusButton_2_View* pNotePaper;
@property(nonatomic,strong)StatusButton_2_View* pCutPaper;
@property(nonatomic,strong)StatusButton_2_View* pDrawPaper;
//
@property(nonatomic,strong)StatusButton_2_ViewDefine* pDrawPen;
@property(nonatomic,strong)StatusButton_2_ViewDefine* pDrawLine;
@property(nonatomic,strong)StatusButton_2_ViewDefine* pDrawColor;
@property(nonatomic,strong)StatusButton_2_ViewDefine* pDrawEraser;
@property(nonatomic,strong)StatusButton_2_View* pDrawClear;
//
@property(nonatomic,strong)PaintToolInfo* paintToolInfo;
//其他扩展类中实现的
@property(nonatomic,assign)BOOL memoUnShow; //便签功能是否开启
@property(nonatomic,assign)BOOL cutUnShow;  //剪报功能是否开启
@property(nonatomic,assign)BOOL drawUnShow; //涂鸦功能是否开启
//
@end

@implementation ReadBookVOrH_VC (FloatBtns_Pep)

//学习下按钮
ASSOCIATED(pFView, setPFView, FloatBtnView_Pep*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pFHomeBtn, setPFHomeBtn, StatusButton_3_View*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pNotesModelBtn, setPNotesModelBtn, StatusButton_2_View*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pGrammarModelBtn, setPGrammarModelBtn, StatusButton_2_View*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pWordsModelBtn, setPWordsModelBtn, StatusButton_2_View*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pTransModelBtn, setPTransModelBtn, StatusButton_2_View*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pReadModelBtn, setPReadModelBtn, StatusButton_2_View*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

//编辑下按钮
ASSOCIATED(pNotePaper, setPNotePaper, StatusButton_2_View*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pCutPaper, setPCutPaper, StatusButton_2_View*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pDrawPaper, setPDrawPaper, StatusButton_2_View*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
//
ASSOCIATED(pDrawPen, setPDrawPen, StatusButton_2_ViewDefine*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pDrawLine, setPDrawLine, StatusButton_2_ViewDefine*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pDrawColor, setPDrawColor, StatusButton_2_ViewDefine*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pDrawEraser, setPDrawEraser, StatusButton_2_ViewDefine*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ASSOCIATED(pDrawClear, setPDrawClear, StatusButton_2_View*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

//画图选择工具信息
ASSOCIATED(paintToolInfo, setPaintToolInfo, PaintToolInfo*, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
//
ASSOCIATED_BOOL(memoUnShow, setMemoUnShow);
ASSOCIATED_BOOL(cutUnShow, setCutUnShow);
ASSOCIATED_BOOL(drawUnShow, setDrawUnShow);

+ (void)load
{
    [self swizzleSelector:@selector(viewDidLoad) withSelector:@selector(viewDidLoad_floatBtns_pep)];
    [self swizzleSelector:@selector(readViewDidLoadSuccess_PageView:) withSelector:@selector(readViewDidLoadSuccess_PageView_floatBtns_pep:)];
    [self swizzleSelector:@selector(readViewDidScrolledTo:) withSelector:@selector(readViewDidScrolledTo_floatBtns_pep:)];
    [self swizzleSelector:@selector(readViewDidTapWord:) withSelector:@selector(readViewDidTapWord_floatBtns_pep:)];
    [self swizzleSelector:NSSelectorFromString(@"didTapSelfView:") withSelector:@selector(didTapSelfView_pep:)];
    [self swizzleSelector:@selector(dealloc_My) withSelector:@selector(dealloc_My_floatBtns_pep)];
}

- (void)dealloc_My_floatBtns_pep
{
    [self dealloc_My_floatBtns_pep];
//    self.pFView = nil;
//    self.pFHomeBtn = nil;
//    self.pNotesModelBtn = nil;
//    self.pGrammarModelBtn = nil;
//    self.pWordsModelBtn = nil;
//    self.pTransModelBtn = nil;
//    self.pReadModelBtn = nil;
//    //
//    self.pNotePaper = nil;
//    self.pCutPaper = nil;
//    self.pDrawPaper = nil;
//    //
//    self.pDrawPen = nil;
//    self.pDrawLine = nil;
//    self.pDrawColor = nil;
//    self.pDrawEraser = nil;
//    self.pDrawClear = nil;
//    //
//    self.paintToolInfo = nil;
}

- (void)didTapSelfView_pep:(UITapGestureRecognizer*)tap
{
    if (!self.pNotesModelBtn.onOff) {
        [self didTapSelfView_pep:tap];
    }
}

- (void)viewDidLoad_floatBtns_pep
{
    //
    PaintToolInfo* ptinfo = [[PaintToolInfo alloc] init];
    self.paintToolInfo = ptinfo;
    ptinfo.colorArr = @[LineColor1,LineColor2,LineColor3,LineColor4,LineColor5,LineColor6,LineColor7,LineColor8,LineColor9];
    ptinfo.colorIndex = 5;
    ptinfo.lineWidthTypeArr = @[LineChoose_thin,LineChoose_normal,LineChoose_bold];
    ptinfo.lineWidthType = LineChoose_normal;
    ptinfo.penArr = @[PenChoose_thin,PenChoose_bold];
    ptinfo.pen = PenChoose_thin;
    //
    [self viewDidLoad_floatBtns_pep];
}

- (void)readViewDidLoadSuccess_PageView_floatBtns_pep:(PageView *)pageView
{
    [self readViewDidLoadSuccess_PageView_floatBtns_pep:pageView];
    [self reflashReadViewStatus_Memo_CutPage_Draw];
    //
    if (pageView == readView.currentPageView) {
        [self reflashFloatViewShow_pep];
    }
}

- (void)readViewDidScrolledTo_floatBtns_pep:(PageView *)pageView
{
    self.paintToolInfo.pageID = pageView.pageId;
    [self readViewDidScrolledTo_floatBtns_pep:pageView];
    if ([self.readSource isEqualToString:ReadSource_Pep]) {
        //
        if (readView.goToPage_Action && readView.goPage.type == GoToPageType_next) {
            readView.goToPage_Action = NO;
        }else{
            [[TLSoundPlayer shareSingle] stopAllFiles];
        }
        [self msgTo_menthed:@"refalshMp3Arr" refs:nil needReturnValue:NO];
        //
        [self reflashFloatViewShow_pep];
        //
        StatusButton_2_View* currentSreadBtn = [self msgTo_menthed:@"currentSreadBtn" refs:nil needReturnValue:YES];
        if (currentSreadBtn) {
            [currentSreadBtn setButtonStatus:NO];
            NSString* type = currentSreadBtn.userInfo[@"type"];
            if (readView.currentPageView.paragraph_suffix
                && readView.currentPageView.paragraph_prev_suffix_index == nil
                && [type isEqualToString:@"paragraph"]) {
                [readView performSelector:@selector(nextPage) withObject:nil afterDelay:2];
            }else if (readView.currentPageView.paragraph_prev_suffix_index.count > 0
                      && [type isEqualToString:@"paragraph"]) {
                [self msgTo_menthed:@"setSreadIndex:" refs:@[readView.currentPageView.paragraph_prev_suffix_index] needReturnValue:NO];
                indexMp3 = [readView.currentPageView.paragraph_prev_suffix_index[0] integerValue];
                longx = 0;
                NSNumber* isPlaying_n = [self msgTo_menthed:@"isPlaying_Mp3Index:" refs:@[@(indexMp3)] needReturnValue:YES];
                if (!isPlaying_n || !isPlaying_n.boolValue) {
                    [DataProcessing do_Main:^{
                        if(indexMp3 >= 0 && indexMp3 < mp3Arr.count)[self msgTo_menthed:@"playBookSound_Continue" refs:nil needReturnValue:NO];
                    } delay:0.1];
                }
                
            }
            //
            if (readView.currentPageView.article_suffix
                && readView.currentPageView.article_prev_suffix_index == nil
                && [type isEqualToString:@"article"]) {
                [readView performSelector:@selector(nextPage) withObject:nil afterDelay:2];
            }else if (readView.currentPageView.article_prev_suffix_index.count > 0
                      && [type isEqualToString:@"article"]) {
                [self msgTo_menthed:@"setSreadIndex:" refs:@[readView.currentPageView.article_prev_suffix_index] needReturnValue:NO];
                indexMp3 = [readView.currentPageView.article_prev_suffix_index[0] integerValue];
                longx = 0;
                NSNumber* isPlaying_n = [self msgTo_menthed:@"isPlaying_Mp3Index:" refs:@[@(indexMp3)] needReturnValue:YES];
                if (!isPlaying_n || !isPlaying_n.boolValue) {
                    [DataProcessing do_Main:^{
                        if(indexMp3 >= 0 && indexMp3 < mp3Arr.count)[self msgTo_menthed:@"playBookSound_Continue" refs:nil needReturnValue:NO];
                    } delay:0.1];
                }
                
            }
        }
        
        if (readView.goToPage_Action && readView.goPage.type == GoToPageType_prev) {
            readView.goToPage_Action = NO;
            indexMp3 = readView.goPage.index;
            longx = 0;
            [DataProcessing do_Main:^{
                if(indexMp3 >= 0 && indexMp3 < mp3Arr.count)[self msgTo_menthed:@"playBookSound_Continue" refs:nil needReturnValue:NO];
            } delay:0.1];
        }
        
        //更新，模式显示
        [self reflashReadViewStatus_Memo_CutPage_Draw];

        //记录上次阅读页
        UserInfo* uinfo = [[CacheData shareSingle] getUserLoginInfo];
        [[CacheData shareSingle] updateBook:self.bookid OpenPage:pageView.pageIndex forUid:uinfo.uid];
        //
    }
}

- (void)readViewDidTapWord_floatBtns_pep:(KoK_RectView *)rectview
{
    [self readViewDidTapWord_floatBtns_pep:rectview];
    if (![self.readSource isEqualToString:ReadSource_Pep]) {
        return;
    }
    
    if (self.pReadModelBtn.onOff) {
        [[TLSoundPlayer shareSingle] stopAllFiles];
        [self msgTo_menthed:@"cleanStatusForCurrentSreadBtn" refs:nil needReturnValue:NO];
        if (rectview.goPage && rectview.goPage.type == GoToPageType_prev) {
            if (readView.goToPage_Action == NO) {
                readView.goToPage_Action = YES;
                readView.goPage = rectview.goPage;
                if (rectview.goPage.offset == 1) {
                    [readView prevPage];
                }else{
                    [self gotToPageIndex:readView.currentPageView.pageIndex-rectview.goPage.offset];
                }
            }
        }else{
            indexMp3 = rectview.mp3_Index;
            longx = 0;
            [self msgTo_menthed:@"setSreadIndex:" refs:nil needReturnValue:NO];
            if(indexMp3 >= 0 && indexMp3 < mp3Arr.count)[self msgTo_menthed:@"playBookSound_Continue" refs:nil needReturnValue:NO];
        }
    }
    
}


- (void)addFloatView_pep
{
    __weak ReadBookVOrH_VC* wself = self;
    FloatBtnView_Pep* fview = [FloatBtnView_Pep floatBtnsWtihSuperView:self.view];
    self.pFView = fview;
    fview.bookName = self.bookName;
    [self.view addSubview:fview];
    //
    CGRect frame = CGRectMake(0, 0, 10, 10);
    //
    StatusButton_3_View* pFHomeBtn = [[StatusButton_3_View alloc] initWithFrame:frame imageNormal:@"btn_tool_normal.png" imageWork:@"btn_tool_pressed.png" imageForbit:@"btn_tool_back_pressed.png"];
    self.pFHomeBtn = pFHomeBtn;
    [pFHomeBtn setButtonStatus:StatusButton_3_View_Status_work];
    pFHomeBtn.btnClicked = ^(StatusButtonView* sBtn){
        [wself clicked_Home];
    };
    //
    StatusButton_2_View*pNotesModelBtn = [[StatusButton_2_View alloc] initWithFrame:frame imageOn:@"btn_reading_pressed.png" imageOff:@"btn_reading_normal.png"];
    self.pNotesModelBtn = pNotesModelBtn;
    [pNotesModelBtn setButtonStatus:NO];
    pNotesModelBtn.btnClicked = ^(StatusButtonView* sBtn){
        [wself clicked_NotesModel];
    };
    //
    StatusButton_2_View*pWordsModelBtn = [[StatusButton_2_View alloc] initWithFrame:frame imageOn:@"btn_word_pressed.png" imageOff:@"btn_word_normal.png"];
    self.pWordsModelBtn = pWordsModelBtn;
    [pWordsModelBtn setButtonStatus:NO];
    pWordsModelBtn.btnClicked = ^(StatusButtonView* sBtn){
        [wself clicked_studyModel:sBtn];
    };
    //
    StatusButton_2_View*pReadModelBtn = [[StatusButton_2_View alloc] initWithFrame:frame imageOn:@"btn_study_pressed.png" imageOff:@"btn_study_normal.png"];
    self.pReadModelBtn = pReadModelBtn;
    [pReadModelBtn setButtonStatus:YES];
    pReadModelBtn.btnClicked = ^(StatusButtonView* sBtn){
        [wself clicked_studyModel:sBtn];
    };
    //
    StatusButton_2_View*pTransModelBtn = [[StatusButton_2_View alloc] initWithFrame:frame imageOn:@"btn_translate_pressed.png" imageOff:@"btn_translate_normal.png"];
    self.pTransModelBtn = pTransModelBtn;
    [pTransModelBtn setButtonStatus:NO];
    pTransModelBtn.btnClicked = ^(StatusButtonView* sBtn){
        [wself clicked_studyModel:sBtn];
    };
    //
    StatusButton_2_View*pGrammarModelBtn = [[StatusButton_2_View alloc] initWithFrame:frame imageOn:@"btn_grammer_pressed.png" imageOff:@"btn_grammer_normal.png"];
    self.pGrammarModelBtn = pGrammarModelBtn;
    [pGrammarModelBtn setButtonStatus:NO];
    pGrammarModelBtn.btnClicked = ^(StatusButtonView* sBtn){
        [wself clicked_studyModel:sBtn];
    };
    //
    NSMutableArray* mainArr = [NSMutableArray arrayWithCapacity:0];
    if(pNotesModelBtn)[mainArr addObject:pNotesModelBtn];
    if(pTransModelBtn)[mainArr addObject:pTransModelBtn];
    if(pGrammarModelBtn)[mainArr addObject:pGrammarModelBtn];
    if(pWordsModelBtn)[mainArr addObject:pWordsModelBtn];
    if(pReadModelBtn)[mainArr addObject:pReadModelBtn];
    //

    PaintToolInfo* ptinfo = self.paintToolInfo;
    //
    StatusButton_2_View*pNotePaper = [[StatusButton_2_View alloc] initWithFrame:frame imageOn:@"btn_note_pressed.png" imageOff:@"btn_note_normal.png"];
    self.pNotePaper = pNotePaper;
    [pNotePaper setButtonStatus:NO];
    pNotePaper.btnClicked = ^(StatusButtonView* sBtn){
        [wself clicked_noteModel:sBtn];
    };
    //
    StatusButton_2_View*pCutPaper = [[StatusButton_2_View alloc] initWithFrame:frame imageOn:@"btn_scrap_pressed.png" imageOff:@"btn_scrap_normal.png"];
    self.pCutPaper = pCutPaper;
    [pCutPaper setButtonStatus:NO];
    pCutPaper.btnClicked = ^(StatusButtonView* sBtn){
        [wself clicked_noteModel:sBtn];
    };
    //
    StatusButton_2_View*pDrawPaper = [[StatusButton_2_View alloc] initWithFrame:frame imageOn:@"btn_scrawl_pressed.png" imageOff:@"btn_scrawl_normal.png"];
    self.pDrawPaper = pDrawPaper;
    [pDrawPaper setButtonStatus:NO];
    pDrawPaper.btnClicked = ^(StatusButtonView* sBtn){
        [wself clicked_noteModel:sBtn];
        ptinfo.isEraser = NO;
        [wself updatePaintInfo_toolDisplay];
    };
    //
    StatusButton_2_ViewDefine*pDrawPen = [[StatusButton_2_ViewDefine alloc] initWithFrame:frame imageOn:@"circle_blue.png" imageOff:@"circle_grey.png"];
    self.pDrawPen = pDrawPen;
    pDrawPen.viewOn = [[UIImageView alloc] initWithFrame:frame];
    pDrawPen.viewOff = [[UIImageView alloc] initWithFrame:frame];
    [pDrawPen setButtonStatus:NO];
    pDrawPen.btnClicked = ^(StatusButtonView* sBtn){
        ptinfo.isEraser = NO;
        ToolChooseViewController* tcvc = [ToolChooseViewController new];
        tcvc.followView = sBtn;
        tcvc.penType = ptinfo.pen;
        tcvc.showPens = ptinfo.penArr;
        [tcvc ToolChooseShow:ToolChoose_pen fromVC:wself clickBlock:^(ToolChooseViewController *toolVC, NSInteger index) {
            wself.paintToolInfo.pen = toolVC.penType;
            [wself updatePaintInfo_toolDisplay];
            [toolVC close];
        } tapEmptyBlock:^(ToolChooseViewController *toolVC) {
            [(StatusButton_2_ViewDefine*)sBtn setButtonStatus:NO];
        }];
    };
    //
    StatusButton_2_ViewDefine*pDrawLine = [[StatusButton_2_ViewDefine alloc] initWithFrame:frame imageOn:@"circle_blue.png" imageOff:@"circle_grey.png"];
    self.pDrawLine = pDrawLine;
    pDrawLine.viewOn = [[UIImageView alloc] initWithFrame:frame];
    pDrawLine.viewOff = [[UIImageView alloc] initWithFrame:frame];
    [pDrawLine setButtonStatus:NO];
    pDrawLine.btnClicked = ^(StatusButtonView* sBtn){
        //ptinfo.isEraser = NO;
        ToolChooseViewController* tcvc = [ToolChooseViewController new];
        tcvc.followView = sBtn;
        tcvc.lineType = ptinfo.lineWidthType;
        tcvc.showLines = ptinfo.lineWidthTypeArr;
        [tcvc ToolChooseShow:ToolChoose_line fromVC:wself clickBlock:^(ToolChooseViewController *toolVC, NSInteger index) {
            wself.paintToolInfo.lineWidthType = toolVC.lineType;
            [wself updatePaintInfo_toolDisplay];
            [toolVC close];
        } tapEmptyBlock:^(ToolChooseViewController *toolVC) {
            [(StatusButton_2_ViewDefine*)sBtn setButtonStatus:NO];
        }];
    };
    //
    StatusButton_2_ViewDefine*pDrawColor = [[StatusButton_2_ViewDefine alloc] initWithFrame:frame imageOn:@"circle_blue.png" imageOff:@"circle_grey.png"];
    self.pDrawColor = pDrawColor;
    UIView* view = [[UIView alloc] initWithFrame:pDrawColor.bounds];
    view.backgroundColor = ptinfo.color;
    pDrawColor.viewOn = view;
    view = [[UIView alloc] initWithFrame:pDrawColor.bounds];
    view.backgroundColor = ptinfo.color;
    pDrawColor.viewOff = view;
    UIImageView* imgv = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"circle_blue.png"]];
    pDrawColor.viewBg = imgv;
    [pDrawColor setButtonStatus:NO];
    pDrawColor.btnClicked = ^(StatusButtonView* sBtn){
        ptinfo.isEraser = NO;
        ToolChooseViewController* tcvc = [ToolChooseViewController new];
        tcvc.followView = sBtn;
        tcvc.defualtIndex = ptinfo.colorIndex;
        tcvc.ShowColors = ptinfo.colorArr;
        [tcvc ToolChooseShow:ToolChoose_color fromVC:wself clickBlock:^(ToolChooseViewController *toolVC, NSInteger index) {
            wself.paintToolInfo.colorIndex = index;
            [wself updatePaintInfo_toolDisplay];
            [toolVC close];
        } tapEmptyBlock:^(ToolChooseViewController *toolVC) {
            [(StatusButton_2_ViewDefine*)sBtn setButtonStatus:NO];
        }];
    };
    //
    StatusButton_2_ViewDefine*pDrawEraser = [[StatusButton_2_ViewDefine alloc] initWithFrame:frame imageOn:@"btn_eraser_pressed.png" imageOff:@"btn_eraser_normal.png"];
    self.pDrawEraser = pDrawEraser;
    view = [[UIView alloc] initWithFrame:frame];
    pDrawEraser.viewOff = view;
    [pDrawEraser setButtonStatus:ptinfo.isEraser];
    pDrawEraser.btnClicked = ^(StatusButtonView* sBtn){
        StatusButton_2_ViewDefine* sbtn = (StatusButton_2_ViewDefine*)sBtn;
        ptinfo.isEraser = sbtn.onOff;
        [wself updatePaintInfo_toolDisplay];
        if (sbtn.onOff) {
            [sbtn.viewOff.glowLayer reStareGlowAnimation];
        }else{
            [sbtn.viewOff.glowLayer pauseGlowAnimation];
        }
    };
    //
    StatusButton_2_View*pDrawClear = [[StatusButton_2_View alloc] initWithFrame:frame imageOn:@"btn_delete_pressed.png" imageOff:@"btn_delete_normal.png"];
    self.pDrawClear = pDrawClear;
    [pDrawClear setButtonStatus:NO];
    __weak ReadView* wreadView = readView;
    pDrawClear.btnClicked = ^(StatusButtonView* sBtn){
        [UIAlertView tl_showTitle:@"" message:ReadLocalizedString(@"msg_del_draw") didClick:^(UIAlertView * _Nullable alertView, NSInteger buttonIndex) {
            [wself.pDrawClear setButtonStatus:NO];
            if (buttonIndex == 1) {
                ptinfo.isEraser = NO;
                [wself updatePaintInfo_toolDisplay];
                [wreadView.currentPageView.scrawlView clearAndDeletePaints];
            }
        } buttonTitles:ReadLocalizedString(@"cancel"),ReadLocalizedString(@"sure"),nil];
    };

    NSMutableArray* subArr = [NSMutableArray arrayWithCapacity:0];
    if(pNotePaper)[subArr addObject:pNotePaper];
    if(pCutPaper)[subArr addObject:pCutPaper];
    if(pDrawPaper)[subArr addObject:pDrawPaper];
    if(pDrawColor)[subArr addObject:pDrawColor];
    //
    CGFloat wh = 50/ratio_w;
    CGFloat min = 30;//telen 适配小分辨率
    wh = MAX(min, wh);
    //
    pDrawClear.fbv_bool_KeepSizeValue = @(YES);
    pDrawEraser.fbv_bool_KeepSizeValue = @(YES);
    pDrawColor.fbv_bool_KeepSizeValue = @(YES);
    pDrawLine.fbv_bool_KeepSizeValue = @(YES);
    pDrawPen.fbv_bool_KeepSizeValue = @(YES);
    pDrawClear.frame = pDrawEraser.frame = pDrawLine.frame = pDrawColor.frame = pDrawPen.frame = CGRectMake(0, 0, ceil(wh*0.8), ceil(wh*0.8));
    //
    {
        //处理颜色按钮，现状
        pDrawColor.viewOn.frame = pDrawColor.bounds;
        pDrawColor.viewOff.frame = pDrawColor.bounds;
        pDrawColor.viewBg.frame = CGRectInset(pDrawColor.viewOn.frame, ceil(wh*0.15), ceil(wh*0.15));
        [pDrawColor.viewOn viewAddBezierPathWithRoundedRect:CGRectInset(pDrawColor.viewOn.frame, ceil(wh*0.2), ceil(wh*0.2))  byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(wh*0.4, wh*0.4)];
        [pDrawColor.viewOff viewAddBezierPathWithRoundedRect:CGRectInset(pDrawColor.viewOff.frame, ceil(wh*0.14), ceil(wh*0.14))  byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(wh*0.4, wh*0.4)];
        //笔形
        pDrawPen.viewOn.frame = pDrawPen.bounds;
        pDrawPen.viewOff.frame = pDrawPen.bounds;
        //笔形
        pDrawLine.viewOn.frame = pDrawLine.bounds;
        pDrawLine.viewOff.frame = pDrawLine.bounds;
        //橡皮擦
        pDrawEraser.viewOff.frame = pDrawEraser.bounds;
        view = pDrawEraser.viewOff;
        [view viewAddBezierPathWithRoundedRect:view.bounds byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(view.bounds.size.width*0.5, view.bounds.size.height*0.5)];
        Boolean hidd = view.hidden;
        view.hidden = NO;
        view.backgroundColor = [[UIColor blueColor] colorWithAlphaComponent:0.05];
        [view addGlowLayerWithGlowColor:[UIColor blueColor]];
        view.hidden = hidd;
        view.glowLayer.glowRadius        = @(2.f);
        view.glowLayer.glowOpacity       = @(1.f);
        view.glowLayer.glowDuration      = @(1.f);
        view.glowLayer.hideDuration      = @(0.5f);
        view.glowLayer.glowAnimationDuration = @(1.f);
        view.backgroundColor = [UIColor clearColor];
    }
    //
    fview.allBtnSize = CGSizeMake(wh, wh);
    frame = CGRectMake(0, 0, width_my, height_my);
    frame.size.height -= ceil(topBarHeight + pageMapView.mapHeigth);
    frame.size.width -= wh*0;
    frame.origin.y += ceil(topBarHeight);
    frame.origin.x += wh*0;
    fview.canBerthRect = frame;
    fview.ratio_w = ratio_w;
    [fview setHomeBtn:pFHomeBtn mainFloatViews:mainArr subFloatViews:subArr];
    if ([DataProcessing shareSingle].deviceType == DevicesTypes_iPhone && ![self isRotationHorizontal:self.rotation_to]) {
        frame.size.height -= ceil(topBarHeight*0.2);
        frame.origin.y -= ceil(topBarHeight*0.4);
    }
    floatframe_topBar = frame;
    fview.canBerthRect = floatframe_topBar;
    [fview doneSetting];
    //
    frame.origin.y = 0;
    frame.size.height = self.view.bounds.size.height;
    floatframe_full = frame;
    //
    [self performSelector:@selector(reflashFloatViewShow_pep) withObject:nil afterDelay:0.3f];
}

- (void)updatePaintInfo_toolDisplay
{
    PaintToolInfo* ptinfo = self.paintToolInfo;
    readView.currentPageView.scrawlView.lineWidth = ptinfo.lineWidth;
    readView.currentPageView.scrawlView.color = ptinfo.color;
    readView.currentPageView.scrawlView.isEarser = ptinfo.isEraser;
    readView.currentPageView.scrawlView.drawLineRatio = LinesRatio;
    //颜色
    self.pDrawColor.viewOn.backgroundColor = ptinfo.color;
    self.pDrawColor.viewOff.backgroundColor = ptinfo.color;
    //笔
    NSString* onImg = [ToolChooseViewController tcNormalImgForType:ptinfo.pen];
    NSString* offImg = [ToolChooseViewController tcHeightlightImgForType:ptinfo.pen];
    [(UIImageView*)self.pDrawPen.viewOn setImage:[UIImage imageNamed:onImg]];
    [(UIImageView*)self.pDrawPen.viewOff setImage:[UIImage imageNamed:offImg]];
    //线
    onImg = [ToolChooseViewController tcNormalImgForType:ptinfo.lineWidthType];
    offImg = [ToolChooseViewController tcHeightlightImgForType:ptinfo.lineWidthType];
    [(UIImageView*)self.pDrawLine.viewOn setImage:[UIImage imageNamed:onImg]];
    [(UIImageView*)self.pDrawLine.viewOff setImage:[UIImage imageNamed:offImg]];
    //橡皮擦
    if(self.pDrawEraser.onOff != ptinfo.isEraser)[self.pDrawEraser setButtonStatus:ptinfo.isEraser];
}

- (void)reflashFloatViewShow_pep
{
    if(readView.currentPageView.pageType != BookPageType_pContent
       || readView.currentPageView.isDataDisplay == NO
       ){
        [self.pFView unShow];
    }else{
        [self.pFView show];
        [self.pFView fold_Sub];
        NSMutableArray* mainArr = [NSMutableArray arrayWithCapacity:0];
        if (!self.memoUnShow || !self.cutUnShow || !self.drawUnShow) {
            if (self.pNotesModelBtn)[mainArr addObject:self.pNotesModelBtn];
        }
        //if (self.pTransModelBtn)[mainArr addObject:self.pTransModelBtn];
        //if (self.pGrammarModelBtn)[mainArr addObject:self.pGrammarModelBtn];
        //if (self.pWordsModelBtn)[mainArr addObject:self.pWordsModelBtn];
        if (self.pReadModelBtn)[mainArr addObject:self.pReadModelBtn];
        //
        [self.pFView reLayLoutMainFloatViews:mainArr];
        //
    }
}

- (void)reflashReadViewStatus_Memo_CutPage_Draw
{
    [readView updatePagesMemosToShow:!self.memoUnShow];
    [readView updatePagesCutToShow:!self.cutUnShow];
    [readView updatePagesDrawToShow:!self.drawUnShow];
}

#pragma mark-
- (void)stopStudy_ex:(StatusButtonView*)sbtn
{
    //业务互斥处理
    if (sbtn != self.pReadModelBtn) {
        [[TLSoundPlayer shareSingle] stopAllFiles];
        [self msgTo_menthed:@"cleanStatusForCurrentSreadBtn" refs:nil needReturnValue:NO];
        [readView.currentPageView update_KOK_toPlayMSecond:0 andSentenceIndex:0];
    }
    if (sbtn != self.pWordsModelBtn) {
        WordsView* wordsView = [self msgTo_menthed:@"wordsView" refs:nil needReturnValue:YES];
        if (wordsView) {
            [wordsView unShow];
        }
    }
}

#pragma mark-

- (void)clicked_Home
{
    nextSwipe.enabled = preSwipe.enabled = YES;
    if (self.pFHomeBtn.status == StatusButton_3_View_Status_work) {
        [self.pFHomeBtn setButtonStatus:StatusButton_3_View_Status_normal];
        [self.pFView fold_Main];
        [self.pFView fold_Sub];
    }else if (self.pFHomeBtn.status != StatusButton_3_View_Status_work) {
        [self stopStudy_ex:nil];
        [self.pFHomeBtn setButtonStatus:StatusButton_3_View_Status_work];
        [self.pNotesModelBtn setButtonStatus:NO];
        [self.pFView unfold_Main];
        [self.pFView fold_Sub];
        //
        [readView.currentPageView do_normalLayer_scrawl_scrap_memo];
        [self msgTo_menthed:@"didTapSelfView_unShowMemoView" refs:nil needReturnValue:NO];
        [readView.currentPageView msgTo_menthed:@"save_ModyMemos" refs:@[] needReturnValue:NO];
        [readView.currentPageView msgTo_menthed:@"save_ModyScrawl" refs:@[] needReturnValue:NO];
        [readView.currentPageView msgTo_menthed:@"save_ModyScrap" refs:@[] needReturnValue:NO];
    }
}

//进入编辑
- (void)clicked_NotesModel
{
    nextSwipe.enabled = preSwipe.enabled = NO;
    [self msgTo_menthed:@"hideTopBarView" refs:nil needReturnValue:NO];
    [self stopStudy_ex:nil];
    //
    [self.pFHomeBtn setButtonStatus:StatusButton_3_View_Status_work2];
    [self.pNotesModelBtn setButtonStatus:YES];
    [self.pFView fold_Main];
    //
    StatusButtonView* toModelBtn = nil;
    if (self.pDrawPaper && !self.drawUnShow) toModelBtn = self.pDrawPaper;
    if (self.pCutPaper && !self.cutUnShow) toModelBtn = self.pCutPaper;
    if (self.pNotePaper && !self.memoUnShow) toModelBtn = self.pNotePaper;
    [self clicked_noteModel:toModelBtn];
}

//学习模式下的按钮
- (void)clicked_studyModel:(StatusButtonView*)sbtn
{
    NSMutableArray* mainArr = [NSMutableArray arrayWithCapacity:0];
    if (self.pNotesModelBtn)[mainArr addObject:self.pNotesModelBtn];
    if (self.pTransModelBtn)[mainArr addObject:self.pTransModelBtn];
    if (self.pGrammarModelBtn)[mainArr addObject:self.pGrammarModelBtn];
    if (self.pWordsModelBtn)[mainArr addObject:self.pWordsModelBtn];
    if (self.pReadModelBtn)[mainArr addObject:self.pReadModelBtn];
    [mainArr enumerateObjectsUsingBlock:^(StatusButton_2_View*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if (obj == sbtn) {
            [obj setButtonStatus:YES];
        }else{
            [obj setButtonStatus:NO];
        }
    }];
    [self stopStudy_ex:sbtn];
}

- (void)clicked_noteModel:(StatusButtonView*)sbtn
{
    NSMutableArray* subArr = [NSMutableArray arrayWithCapacity:0];
    if(self.pDrawPaper && !self.drawUnShow){
        if (sbtn == self.pDrawPaper) {
            if(self.pDrawClear)[subArr addObject:self.pDrawClear];
            if(self.pDrawEraser)[subArr addObject:self.pDrawEraser];
            if(self.pDrawColor)[subArr addObject:self.pDrawColor];
            if(self.pDrawLine)[subArr addObject:self.pDrawLine];
            if(self.pDrawPen)[subArr addObject:self.pDrawPen];
            [self.pDrawPaper setButtonStatus:YES];
            [self updatePaintInfo_toolDisplay];
        }else{
            [self.pDrawPaper setButtonStatus:NO];
        }
        [subArr addObject:self.pDrawPaper];
        [self msgTo_menthed:@"didTapSelfView_unShowMemoView" refs:nil needReturnValue:NO];
    }
    if(self.pCutPaper && !self.cutUnShow){
        if (sbtn == self.pCutPaper) {
            [self.pCutPaper setButtonStatus:YES];
        }else{
            [self.pCutPaper setButtonStatus:NO];
        }
        [subArr addObject:self.pCutPaper];
        [self msgTo_menthed:@"didTapSelfView_unShowMemoView" refs:nil needReturnValue:NO];
    }
    if(self.pNotePaper && !self.memoUnShow){
        if (sbtn == self.pNotePaper) {
            [self.pNotePaper setButtonStatus:YES];
        }else{
            [self.pNotePaper setButtonStatus:NO];
        }
        [subArr addObject:self.pNotePaper];
    }
    //
    TLEventView* eventView = nil;
    if (sbtn == self.pNotePaper && !self.memoUnShow) eventView = readView.currentPageView.memoView;
    if (sbtn == self.pCutPaper && !self.cutUnShow) eventView = readView.currentPageView.scrapView;
    if (sbtn == self.pDrawPaper && !self.drawUnShow) eventView = readView.currentPageView.scrawlView;
    [readView.currentPageView do_foucusLayer_scrawl_scrap_memo:eventView];
    //
    //按钮选择显示
    [self.pFView reLayLoutSubFloatViews:subArr];
    //
    NSString *pageStr = readView.currentPageView.pageId;
    NSString *opStr = nil;
    if ([self.paintToolInfo.pen isEqualToString:PenChoose_thin]) { //画笔
        opStr = @"pen";
    }else if ([self.paintToolInfo.pen isEqualToString:PenChoose_bold]) { //荧光笔
        opStr = @"mark";
    }
    if ([subArr containsObject:self.pDrawEraser] && [subArr containsObject:self.pDrawColor] && self.pDrawPaper.onOff) {
        //Pep统计:画笔开始
        if (pageStr && opStr) {
            NSDictionary *opDict = [NSDictionary dictionaryWithObjectsAndKeys:opStr,@"op",@(self.bookid).description,@"bid",pageStr,@"pg",@(1).description,@"opc", nil];
            [NSObject msgToTarget:self menthed:@"pepSatisticSrouce_read:isBegin:" refs:@[opDict,@(YES)] needReturnValue:NO];
        }
    }else  {
        //Pep统计:画笔结束
        if (pageStr && opStr) {
            NSDictionary *opDict = [NSDictionary dictionaryWithObjectsAndKeys:opStr,@"op",@(self.bookid).description,@"bid", pageStr,@"pg", @(1).description,@"opc",nil];
            [NSObject msgToTarget:self menthed:@"pepSatisticSrouce_read:isBegin:" refs:@[opDict,@(NO)] needReturnValue:NO];
        }
    }
}

@end
